//
//  ViewController2.m
//  20201
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController2.h"

@interface ViewController2 ()
@property (weak, nonatomic) IBOutlet UISwitch *wrapSwitch;
@property (weak, nonatomic) IBOutlet UISlider *wrapSpeedSlider;

@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self updateInfo];
    
    //监听程序进入前台的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInfo) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (IBAction)backBtnPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)wrapSwitch:(UISwitch *)sender {
    
    NSUserDefaults *d=[NSUserDefaults standardUserDefaults];
    [d setBool:sender.on forKey:@"wrap"];
    
    [d synchronize];
}
- (IBAction)wrapSpeedSlider:(UISlider *)sender {
    
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    
    [d setFloat:sender.value forKey:@"wrapSpeed"];
    
    [d synchronize];
}

-(void)updateInfo{
    NSUserDefaults *d=[NSUserDefaults standardUserDefaults];
    self.wrapSwitch.on=[d boolForKey:@"wrap"];
    self.wrapSpeedSlider.value=[d floatForKey:@"wrapSpeed"];
}
@end
